
import React from 'react';
import {Form, Row, Col, Button, DatePicker, message ,Divider,Select} from 'antd';
import StatisticsBox from '../../components/box/statistics';
import {sessionManager} from '../../utils/sessionStorage';
import AdjustHis from './AdjustHis';
import {injectIntl} from 'react-intl';
import Grid from '../../components/table/grid';
import tranStartType from '../../utils/tranStartType';
import axios from 'axios';
import moment from 'moment';
import { getYear } from '../../utils/Array';
import qs from 'qs';

class ledgerMonthDetail extends React.Component {
  constructor(props) {
    super(props);
    this.common = this.props.intl.messages.common;
    this.columns = [
      {
        title: '分账日期',
        width: '150',
        dataIndex:'settlementDay',
        key: 'settlementDay'
      },
      {
        title: '应分电量 (KWH)',
        dataIndex: 'electric',
        key: 'electric',
        width: '150',
      },
      {
        title: '应分电费（元）',
        dataIndex: 'electricAmount',
        key: 'electricAmount',
        width: '150',
      },
      {
        title: '应分服务费（元）',
        dataIndex: 'serviceAmount',
        key: 'serviceAmount',
        width: '150',
      },
      {
        title: '应分总费用（元）',
        dataIndex: 'totalAmount',
        key: 'totalAmount',
        width: '150',
      },
      {
        title: this.common.operation,
        key: 'action',
        fixed: 'right',
        width: 100,
        render: (text, record) => (
          <span>
                        <a onClick={() => this.goLink(text, record, 'ledgerMonthOrderList')}>订单明细</a>
                    </span>
        )
      }
    ];
    this.state = {
      params:{
        userId:''
      }
    }
  }

  componentWillMount() {
    if (this.props.location.state) {
      const monthDetailParams = {
        userId: this.props.location.state.record ? this.props.location.state.record.userId: '',
        timeBegin: this.props.location.state.params.timeBegin,
        timeEnd: this.props.location.state.params.timeEnd
      };
      sessionManager.set('monthDetailParams', JSON.stringify(monthDetailParams));
      this.setState({
        params: monthDetailParams
      });
    } else {
      this.setState({
        params: JSON.parse(sessionManager.get('monthDetailParams'))
      });
    }
   
  }

  goLink = (text, record, link) => {
    if(this.props.location.state){
      sessionManager.set('ym',this.props.location.state.ym);
    }
    sessionManager.set('settlementDate',text.settlementDay);
    this.props.history.push({pathname: `/finance/${link}`});
  };

  render() {
    return (
      <div>
        <Grid url="api/settlement/billSplit/settlementDetail" columns={this.columns}   params={this.state.params}/>
      </div>
    )
  }
}

// ledgerMonthDetail = createForm()(ledgerMonthDetail);
export default injectIntl(ledgerMonthDetail)
